<!DOCTYPE html >
<html>
<head>
    <base>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>药品库存记录明细</title>
    <link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
    <style>
        body {
            margin: 10px;
        }
    </style>
</head>
<body>

<table class="layui-hide" id="goods" lay-filter="demo"></table>

<script src="/res/layui-v2.5.6/layui.js"></script>
<script src="/res/js/util.js"></script>
<script>
    var openIndex = null;
    var table = null;
    layui.use(['form', 'laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function () {
        table = layui.table;
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            , layer = layui.layer //弹层
            //, table = layui.table //表格
            , upload = layui.upload //上传
            , form = layui.form
            , element = layui.element //元素操作
            , $ = layui.$;
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //监听Tab切换
        element.on('tab(demo)', function (data) {
            layer.msg('切换了：' + this.innerHTML);
            console.log(data);
        });
        //获取判断是否为总公司
        var url = null;
        var cols = null;
        //判断是否为总公司
        if(whetherZGS()){
            url = "/hqInventory/findByRepertoryId";
            cols = [[
                {field: 'wareId', title: '序号', width: 100, fixed: 'left', align: 'center',type: 'numbers',unresize: true, sort: 'true', totalRowText: '合计'}
                , {field: 'drugName', title: '药品名称', align:"center"}
                , {field: 'typeName', title: '药品类型', align:"center"}
                , {field: 'state', title: '出/入账', align:"center",templet:function (d) {
                        if(d.state=='1'){
                            return '<p class="layui-btn layui-btn-normal layui-btn-xs">入库</p>'
                        }else {
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">出库</p>';
                        }
                    }}
                , {field: 'wareNum', title: '数量', width: 120, totalRow: true, align:"center"}
                , {field: 'wareTime', title: '出入库时间', width: 200, align:"center"}
                , {field: 'oper', title: '操作人', width: 120, align:"center"}
                , {fixed: 'right',field: 'remark', title: '备注', width: 120, align:"center"}
            ]];
        }else {
            url = "/immRepertory/findByRepertoryId";
            cols = [[
                {field: 'appearId', title: '序号', width: 100, fixed: 'left', align: 'center',type: 'numbers',unresize: true, sort: 'true', totalRowText: '合计'}
                , {field: 'drugName', title: '药品名称', align:"center"}
                , {field: 'typeName', title: '药品类型', align:"center"}
                , {field: 'status', title: '出/入账', align:"center",templet:function (d) {
                        if(d.status=='1'){
                            return '<p class="layui-btn layui-btn-normal layui-btn-xs">入库</p>'
                        }else {
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">出库</p>';
                        }
                    }}
                , {field: 'appearCount', title: '数量', width: 120, totalRow: true, align:"center"}
                , {field: 'optime', title: '出入库时间', width: 120, align:"center"}
                , {field: 'operator', title: '操作人', width: 120, align:"center"}
                , {fixed: 'right',field: 'remark', title: '备注', width: 120, align:"center"}
            ]];
        }


        //执行一个 table 实例
        table.render({
            elem: '#goods'
            , url: url //数据接口
            , page: true //开启分页
            , totalRow: true  //开启合计
            , method: 'post'
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,height:600
            , cols: cols
            , id: 'testReload'
            , where: {
                id: getQueryString("id")
            }
            , parseData: function (res) {
                let jin = null;
                let chu = null;
                $.each(res.data,function(index,item){
                    if(whetherZGS()){
                        if (item.state==1){
                            jin+=item.wareNum
                        }else {
                            chu+=item.wareNum
                        }
                    }else{
                        if (item.status==1){
                            jin+=item.appearCount
                        }else {
                            chu+=item.appearCount
                        }
                    }
                });
                let num = null;
                if(whetherZGS()){
                    num =  {
                        wareNum : jin - Math.round(chu * 100) / 100
                    };
                }else{
                    num =  {
                        appearCount : jin - Math.round(chu * 100) / 100
                    };
                }
                return {
                    "code": res.code, //解析接口状态
                    "count": res.count, //解析数据长度
                    "msg":res.msg,
                    "data":res.data,
                    "totalRow": num
                };
            }
        });

    });
</script>
</body>
</html>